#include <bits/stdc++.h>

using namespace std;

typedef class TwoStackinOneArray {
public:
    TwoStackinOneArray(int capacity) {
        this->capacity = capacity;
        array = new int[capacity];
        topidx[0] = -1;
        topidx[1] = capacity;
        size[0] = size[1] = 0;
    }
    ~TwoStackinOneArray() {
        delete[]array;
        array = nullptr;
    }
    void push(int content, int stackid = 0) {
        if (isfull() || stackid > 1 || stackid < 0)
            return;
        topidx[stackid] += stackid == 0 ? 1 : - 1;
        array[topidx[stackid]] = content;
        size[stackid]++;
    }

    void pop(int stackid = 0) {
        if (isempty(stackid))
            return;
        topidx[stackid] += stackid == 0 ? - 1 : 1;
        size[stackid]--;
    }

    int top(int stackid = 0) {
        if (isempty(stackid))
            return NULL;
        return array[topidx[stackid]];
    }

    bool isfull() {
        return size[0] + size[1] >= capacity;
    }

    bool isempty(int stackid = -1) {
        if(stackid == -1)
            return size[0] + size[1] == 0;
        else if(stackid == 0 || stackid == 1)
            return size[stackid] == 0;
        return true;
    }

    
private:
    int topidx[2];
    int *array;
    int capacity;
    int size[2];
}TwoStack;

int main() {
    TwoStack *ts = new TwoStack(10);
    cout << ts->isempty() << endl;
    for (int i = 0; i <= 10; i++)
        ts->push(i);
    cout << ts->isfull() << " " << ts->top() << endl;
    ts->push(20, 1);
    cout << ts->isfull() << " " << ts->top() << endl;
    ts->pop(1);
    cout << ts->isfull() << " " << ts->top() << endl;
    ts->pop(0);
    cout << ts->isfull() << " " << ts->top() << endl;
    ts->push(20, 1);
    cout << ts->isfull() << " " << ts->top() << endl;
    
    cout << ts->top(0) << "  " << ts->top(1) << endl;
    delete ts;
    //system("pause");
    return 0;
}
